import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Solution {

    static List<String> orgStrs = new ArrayList<String>();

    static int          nStrs   = 0;

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(String[] args) throws NumberFormatException,
            IOException {

        Solution sln = new Solution();
        sln.doWork();
    }
    
    int min(int a, int b)
    {
        return a > b ? b : a;
    }
    
    long CalcSimilaritySum(String str)
    {
        long count = 0;
        int[] previousMatch = new int[11];
        for(int i = 0; i < 11; i++)
        {
            previousMatch[i] = 0;
        }
        int[] xRep = new int[11];
        xRep[0] = -1000000; // bad slot
        xRep[1] = 1;
        
        for(int i = 1; i < 11; i++)
        {
            int rep = i;
            while(rep < str.length() && str.charAt(rep) == str.charAt(rep - i))
            {
                rep++;
            }
            xRep[i] = (rep / i);
        }
        
        for(int i = 1; i < str.length(); i++)
        {
            String suffix = str.substring(i);
            int match = 0;
            for(int x = 1; x < 11; x++)
            {
                if(previousMatch[x] > 0 && i % x == 0)
                {
                    int alreadyMatch = min(previousMatch[x] / x - 1, xRep[x] - 1) * x;
                    if(alreadyMatch - 1 > match)
                    {
                        match = alreadyMatch;
                    }
                }
            }

            for(int j = match; j < suffix.length(); j++)
            {
                if(str.charAt(j) == suffix.charAt(j))
                {
                    match++;
                }
                else
                {
                    break;
                }
            }
            count += match;
            for(int x = 10; x > 1; x--)
            {
                previousMatch[x] = previousMatch[x-1];
            }
            previousMatch[1] = match;
        }
        return count + str.length();
    }
    
    public void doWork() throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        nStrs = Integer.parseInt(in.readLine());
        while (nStrs-- > 0) {
            String input = in.readLine();
            System.out.println(CalcSimilaritySum(input));
        }

    }

}
